<?php
	
	header('Content-type: text/html; charset=utf-8');
	if(!isset($_SESSION)){
		session_start();
	}

	$pdo = null;
	try {
	    $pdo = new PDO('sqlite:mydb1.db');
	    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
	} catch (PDOException $e) {
	    die("连接失败: " . $e->getMessage());
	}


	if(isset($_GET['tuijie'])){
		$arr1 = array();
		foreach($pdo->query('SELECT * FROM bokeWen ORDER BY id DESC LIMIT 3') as $row){
			array_push($arr1,$row);
		} 
		echo json_encode($arr1);
		return; 
	}

	if(isset($_GET['bofaSu'])){
		$user_uid = $_GET['user_uId'];
		$id1 = $_GET['id'];
		$sql3 = "INSERT INTO userDetail (uid, bokeId, type1) VALUES(?,?,?)";
		$stmt = $pdo->prepare($sql3);
		$stmt->execute([$user_uid,$id1,'bofa']);
		$obj1 = new stdClass(); // 初始化对象
		$obj1->msg = "ok";
		echo json_encode($obj1);
		return;
	}

	if(isset($_GET['souc'])){
		$user_uid = $_GET['user_uId'];
		$id1 = $_GET['id'];
		$sql3 = "SELECT * FROM userDetail WHERE 
					uid = '$user_uid' 
					AND bokeid = $id1
					AND type1 = 'souc'
				";
		$stmt = $pdo->query($sql3);
		$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
		if(count($result) > 0){
			$obj2 = array("msg"=>"already");
			echo json_encode($obj2);
			return;
		}else{ 
			$sql4 = "INSERT INTO userDetail (uid, bokeId, type1) VALUES(?,?,?)";
			$stmt = $pdo->prepare($sql4);
			$stmt->execute([$user_uid,$id1,'souc']);
		}
		$obj1 = new stdClass(); // 初始化对象
		$obj1->msg = "ok";

		echo json_encode($obj1);
		return;
	}
// $age=array("aa"=>"11","bb"=>"22","cc"=>"33");
?>